<!--
 - Copyright (C) 2002-2007 WUZEWEN. All rights reserved.
 - WUZEWEN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 -->

<%--
 - <p>http请求，列出当前文件夹下面的文件、文件夹信息，同时对文件提供链接。
 -     放在pda系统中和防在note_... 文件加下面唯一的区别是修改 logo.gif 文件的位置。
 - call it by: response.sendRedirect(
 -		'/manager/wzw_note_tomcat/zeven_fileList.jsp?path='+request.getRequestURI() ); </p>
 - @author WUZEWEN on 2007-2-12
 - @version	1.0
 - @since	JDK1.4,Weblogic815, GB2312
 - <p>Modify logs:
 -		2007-2-12 by WZW: 其实该功能在Tomcat和Weblogic中都提供了，可以设置，所以可以不需要本文件，
 -			完全是徒劳无功。 唯一的好处就是我可以定制、增加更多的功能，如文件删除。
 -		  要多利用已有的、别人提供的东西，而不必花没有必要的精力。
 -		  不要闭门造车、闭关守国；
 -		  人力不若牛、行不若马，而牛马为用，何也？善假于物也！<br />
 -    <tr style='display:block'>  替为 <tr> ，前者引起td布局在fx下面有问题。
 -
 - </p>
 --%>

<%@ page language="java" contentType="text/html; charset=UTF-8" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Zeven's 文件列表页面</title>

<style>
H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}  table {
    width: 100%;
  }
  td.page-title {
    text-align: center;
    vertical-align: top;
    font-family:sans-serif,Tahoma,Arial;
    font-weight: bold;
    background: white;
    color: black;
  }
  td.title {
    text-align: left;
    vertical-align: top;
    font-family:sans-serif,Tahoma,Arial;
    font-style:italic;
    font-weight: bold;
    background: #8C8CFF; /*#D2A41C*/
  }
  td.header-left {
    text-align: left;
    vertical-align: top;
    font-family:sans-serif,Tahoma,Arial;
    font-weight: bold;
    background: #FFDC75;
  }
  td.header-center {
    text-align: center;
    vertical-align: top;
    font-family:sans-serif,Tahoma,Arial;
    font-weight: bold;
    background: #FFDC75;
  }
  td.row-left {
    text-align: left;
    vertical-align: middle;
    font-family:sans-serif,Tahoma,Arial;
    color: black;
    background: white;
  }
  td.row-center {
    text-align: center;
    vertical-align: middle;
    font-family:sans-serif,Tahoma,Arial;
    color: black;
    background: white;
  }
  td.row-right {
    text-align: right;
    vertical-align: middle;
    font-family:sans-serif,Tahoma,Arial;
    color: black;
    background: white;
  }
  TH {
    text-align: center;
    vertical-align: top;
    font-family:sans-serif,Tahoma,Arial;
    font-weight: bold;
    background: #FFDC75;
  }
  TD {
    text-align: center;
    vertical-align: middle;
    font-family:sans-serif,Tahoma,Arial;
    color: black;
    background: white;
  }
</style>

<style>

/* 2005-05-19 WZW 定义列表格式如下： */
.tblContent a{
	border:1px solid #487AA9;
	border-left:0px;
	border-top:0px;
}
.tblContent td{
	border-left:1px solid #487AA9;
	border-top:1px solid #487AA9;
	background-color:#FFFFFF;
	height: 18px;
}

</style>

<%
request.setCharacterEncoding("utf-8"); 
String path = request.getParameter("path");
if(path==null){
	path = request.getRequestURI();	//.../index.jsp
}
// 解决WebLogic下面request.getRequestURI带有文件名的问题。Tomcat不存在该问题。
if( path.endsWith("index.jsp") ){
	path=path.substring( 0, path.lastIndexOf("index.jsp") );
}
System.out.println( "    Client is " + request.getRemoteHost() +", path = " + path );

//System.out.println("path======="+path);
//path = path.substring(0, path.lastIndexOf("/") );

String realPath = request.getRealPath( path );
//if( path.indexOf("..")>-1 ){
//	path=path.substring( path.indexOf("/") );
//	realPath = request.getRealPath( path.substring( path.indexOf("/", 3) ) );
//}else{
//	realPath = request.getRealPath( path );
//}

if( request.getParameter("realPath")!=null){
	realPath = request.getParameter("realPath");	//.../index.jsp
}


java.io.File file = new java.io.File( realPath );
realPath = file.getPath();	//修正
//System.out.println(realPath);

String[] fileNames= file.list();
java.io.File[] files = file.listFiles();

if(!file.exists()){
	out.println("<font size=\"3\" color=\"#FF0000\"><br />当前目录:" + realPath  +" 下不存在文件。\n</font>");
	out.close();
	//throw new Exception("当前项目的项目路径:"+realPath +" 不存在。\n"); //会跳转到 error.jsp
}

%>

</head>

<body bgcolor="#FFFFFF">
<table cellspacing="4" width="100%" border="0">
 <tr>
  <td colspan="2">
   <a href="http://jakarta.apache.org/">
    <img border="0" alt="All Zeven's Web Projects" align="left"
         src="/pda/common/image/logo.gif">
   </a>
   <!--
	<a href="http://jakarta.apache.org/tomcat/">
    <img border="0" alt="The File Manager/Link Page"
         align="right" src="/pda/common/image/logo.gif">
   </a>
   //-->
  </td>
 </tr>
</table>

<hr size="1" noshade="noshade">
<table cellspacing="4" width="100%" border="0">
 <tr>
  <td class="page-title" bordercolor="#000000" align="left" nowrap>
   <font size="+2">Zeven's File List</font>
  </td>
 </tr>
</table>

<br />

<table border="1" cellspacing="0" cellpadding="3">
 <tr>
  <td class="row-left" width="10%"><small><strong>Current Path:</strong></small>&nbsp;</td>
  <td class="row-left">
  		<%=realPath.indexOf(":")<0?realPath:realPath.substring(realPath.indexOf(":")+1)%></td>
 </tr>
</table>

<br />

<table border="1" cellspacing="0" cellpadding="3">
<tr>
 <td colspan="4" class="title">Folers</td>
</tr>

<%
// 1. 文件夹
out.println("<tr>");
int i,j,k=0;
for(i=0,j=0;i<fileNames.length;i++){		
	if( !files[i].isDirectory() ){
		continue;
	}

	if(j%3==0){
		out.print("</tr><tr>");		// 换行
		k++;
	}
	out.print("<td");
	if(k%2==0){
		out.print(" style=\"background-color:#E1E1FF;\"");	// 斑马线
	}
	out.print("><a href='"+path+""+fileNames[i]+"/'>"+fileNames[i]+"</a></td>");
	j++;
}

// 输出转到上级文件夹的链接
if(j%3==0){
	out.print("</tr><tr>");
	k++;
}
// 一定要注意 td 和 style之间空格隔开
out.print("<td"+ (k%2==0?" style=\"background-color:#E1E1FF;\"":"") +"><a href='"+path+"../'>../</a></td>");
j++;

// 补充空td
while( j%3!=0 ){	
	if(k%2==0){
		out.print("<td style='background-color:#E1E1FF;'>&nbsp;</td>");	// 斑马线
	}else{
		out.print("<td>&nbsp;</td>");
	}
	j++;
}

out.println("</tr>");

%>

</table>

<br />

<table border="1" cellspacing="0" cellpadding="3">
<tr>
 <td colspan="5" class="title">Files</td>
</tr>

<%
// 1. 文件
out.println("<tr>");
k=0;
for(i=0,j=0;i<fileNames.length;i++){		
	if( files[i].isDirectory() ){
		continue;
	}
	if(j%3==0){
		out.print("</tr><tr>");  // 换行
		k++;
	}
	//  drop "/" between path and fileName.
	out.print("<td style='text-align:left;");
	if(k%2==0){
		out.print("background-color:#E1E1FF;");	// 斑马线
	}
	out.print("'>·<a target='_blank' href='/pda/fileViewServlet?file="+path+""+fileNames[i]+"'>"+fileNames[i]+"</a></td>");
	j++;
}

// 补充空td
while( j%3!=0 ){
	if(k%2==0){
		out.print("<td style='background-color:#E1E1FF;'>&nbsp;</td>");	// 斑马线
	}else{
		out.print("<td>&nbsp;</td>");
	}
	j++;
}

out.println("</tr>");

%>

</table>

<br />

<hr size="1" noshade="noshade">
<center><font size="-1" color="#525D76">
 <em>Copyright &copy; 2002-2007, KingCore Software Foundation</em></font></center>

<br />

</body>
</html>
